package de.koller.oceanFramework.gl.util;

import de.koller.oceanFramework.tree.ISea3;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;

public class ChildDisplayer {
	
	private ChildDisplayer() {}
	
	public static void show( ISea3 root ) {
		JOptionPane.showMessageDialog( null, new Content( root ), "Childs", JOptionPane.PLAIN_MESSAGE );
	}


	private static class Content extends JPanel {

		private final ISea3 toshow;
		private final JTree tree;
		
		private Content( ISea3 toshow ) {
			this.toshow = toshow;
			
			DefaultMutableTreeNode top = new DefaultMutableTreeNode( toshow.toString() );
			addChilds( toshow, top );
			tree = new JTree( top );
			
			JScrollPane s = new JScrollPane( tree );
			this.add( s );
		}
		
		private void addChilds( ISea3 sea, DefaultMutableTreeNode rep ) {
			
			for( int i = 0; i < sea.childNumber(); i++ ) {
				ISea3 c = sea.getChild( i );
				DefaultMutableTreeNode cr = new DefaultMutableTreeNode( c.toString() );
				rep.add( cr );
				
				addChilds( c, cr );
			}
			
		}
		
	}
	
}
